package com.sharp.core.graphics;

import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;

import com.sharp.core.raytrace.Camera;

public class Java2DGraphic extends Graphic {

	private static class MyFrame extends Frame {
		
		public MyFrame() {
			super();
		}
		
		public void clean(Graphics g) {
			super.paintComponents(g);
		}

		public void drawPixel(Graphics2D g, int x, int y, java.awt.Color c) {
			g.setColor(c);
			g.drawLine(x, y, x, y);
		}

		public void init(int width, int height, int bpp) {
			setSize(width, height);
			setVisible(true);
		}

		public void update() {
		}
	}
	
	private MyFrame frame;
	private java.awt.Color awtColor;
	
	@Override
	public void clean() {
		frame.clean(frame.getGraphics());
	}

	@Override
	public void drawPixel(Camera cam, int x, int y, com.sharp.core.graphics.Color c) {
		x += cam.getStartX();
		y += cam.getStartY();
		awtColor = new Color(c.getR(), c.getG(), c.getB());
		frame.drawPixel((Graphics2D) frame.getGraphics(), x, y, awtColor);
	}

	@Override
	public void init(int width, int height, int bpp) {
		frame = new MyFrame();
		frame.init(width, height, bpp);
		setGraphic(this);
	}

	@Override
	public void update() {
		frame.update();
	}

}
